<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
				xmlns:msxsl="urn:schemas-microsoft-com:xslt"
				xmlns:ext="urn:schemas-microsoft-com:custom:function">

	<xsl:output method="html" indent="yes"/>

	<xsl:template match="/ResultSet">

		<xsl:if test="(Name_0x0020_Match_0x0020_High | Name_x0020_Match_x0020_Relevant)/CONTENTCLASS[. = 'urn:content-class:SPSPeople']/parent::node()[count(.) &gt; 0]">
			<h3>People Name Match Returned</h3>
		</xsl:if>
		<xsl:apply-templates select="(Name_0x0020_Match_0x0020_High | Name_x0020_Match_x0020_Relevant)/CONTENTCLASS[. = 'urn:content-class:SPSPeople']/..">
			<xsl:sort select="*[name()='RANK']" data-type="number" order="descending"/>
			<xsl:sort select="*[name()='TITLE']" order="ascending" data-type="text"/>
		</xsl:apply-templates>

		<!--<xsl:if test="(Name_0x0020_Match_0x0020_High | Name_x0020_Match_x0020_Relevant)/CONTENTCLASS[. = 'urn:content-class:SPSPeople']/parent::node()[count(.) &gt; 0]">
			<h3>Other Matches Returned</h3>
		</xsl:if>
		<xsl:apply-templates select="Name_x0020_Match_x0020_Relevant/CONTENTCLASS[. = 'urn:content-class:SPSPeople']/..">
			<xsl:sort select="*[name()='RANK']" data-type="number" order="desending"/>
			<xsl:sort select="*[name()='TITLE']" order="ascending" data-type="text"/>
		</xsl:apply-templates>-->

		<xsl:if test="*[name(.) != 'Name_0x0020_Match_0x0020_High' and name(.) != 'Name_x0020_Match_x0020_Relevant']/CONTENTCLASS[. = 'urn:content-class:SPSPeople']/parent::node()[count(.) &gt; 0]">
			<h3>People Returned</h3>
		</xsl:if>
		<xsl:apply-templates select="*[name(.) != 'Name_0x0020_Match_0x0020_High' and name(.) != 'Name_x0020_Match_x0020_Relevant']/CONTENTCLASS[. = 'urn:content-class:SPSPeople']/..">
			<xsl:sort select="*[name()='RANK']" data-type="number" order="descending"/>
			<xsl:sort select="*[name()='TITLE']" order="ascending" data-type="text"/>
		</xsl:apply-templates>

		<xsl:if test="*[name(.) != 'Name_0x0020_Match_0x0020_High' and name(.) != 'Name_x0020_Match_x0020_Relevant']/CONTENTCLASS[. != 'urn:content-class:SPSPeople']/parent::node()[count(.) &gt; 0]">
			<h3>Other Items Returned</h3>
		</xsl:if>
		<xsl:apply-templates select="*[name(.) != 'Name_0x0020_Match_0x0020_High' and name(.) != 'Name_x0020_Match_x0020_Relevant']/CONTENTCLASS[. != 'urn:content-class:SPSPeople']/..">
			<xsl:sort select="*[name()='RANK']" data-type="number" order="descending"/>
			<xsl:sort select="*[name()='TITLE']" order="ascending" data-type="text"/>
		</xsl:apply-templates>
	</xsl:template>


	<xsl:template match="Relevant_x0020_Results | Name_0x0020_Match_0x0020_High | Name_x0020_Match_x0020_Relevant">

		<xsl:choose>
			<xsl:when test="CONTENTCLASS[. = 'urn:content-class:SPSPeople']">

				<xsl:call-template name="PersonSearch" />
			</xsl:when>
			<xsl:otherwise>

				<xsl:call-template name="OtherSearch" />
			</xsl:otherwise>
		</xsl:choose>

	</xsl:template>

	<xsl:template name="PersonSearch">
		<xsl:variable name="id" select="WORKID"/>
		<xsl:variable name="url" select="PATH"/>
		<xsl:variable name="email" select="WORKEMAIL"/>
		<xsl:variable name="sip" select="SIPADDRESS"/>
		<xsl:variable name="prefix">IMNRC('</xsl:variable>
		<xsl:variable name="suffix">')</xsl:variable>
		
		<table class="psrch-result" CELLPADDING="0" CELLSPACING="0" BORDER="0" width="100%">
			<tr>
				<td class="psrch-imgcell" width="0%">
					<table class="psrch-profimg" CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="77px" HEIGHT="77px">
						<tr>
							<td align="middle" valign="middle">
								<a href="{$url}" id="{concat('CSR_IMGL_',$id)}" title="{$url}">
									<xsl:variable name="imgid" select="concat('CSR_IMG_',$id)"/>
									<xsl:choose>
										<xsl:when test="pictureurl[. != '']">
											<img id="{$imgid}" src="{PICTUREURL}" alt="{TITLE}" border="0" onload="resizeProfileImage('{$imgid}')"/>
										</xsl:when>
										<xsl:otherwise>
											<img id="{$imgid}" src="/_layouts/images/no_pic.gif" alt="{TITLE}" border="0" onload="resizeProfileImage('{$imgid}')"/>
										</xsl:otherwise>
									</xsl:choose>
									<script>
										window.setTimeout("resizeProfileImage('<xsl:value-of select="$imgid"/>')", 1)
									</script>
								</a>
							</td>
						</tr>
					</table>
				</td>
				<td valign="top" class="psrch-propcell" width="100%">
					<span class="psrch-Title">
						<xsl:choose>
							<xsl:when test="SIPADDRESS[. != '']">
								<img border="0" height="12" width="12" src="/_layouts/images/imnhdr.gif" onload="{concat($prefix, $sip, $suffix)}" ShowOfflinePawn="1" id="{concat('CSRP_',$id,',type=sip')}" />
							</xsl:when>
							<xsl:otherwise>
								<img border="0" height="12" width="12" src="/_layouts/images/imnhdr.gif" onload="{concat($prefix, $email, $suffix)}" ShowOfflinePawn="1" id="{concat('CSRP_',$id,',type=smtp')}" />
							</xsl:otherwise>
						</xsl:choose>
						<a href="{$url}" id="{concat('CSR_',$id)}">
							<xsl:value-of select="TITLE"/>
						</a>
					</span>
					<br/>
					<div class="psrch-Description">
						<xsl:call-template name="DisplayOfficeProfile">
							<xsl:with-param name="title" select="JOBTITLE" />
							<xsl:with-param name="dep" select="DEPARTMENT" />
							<xsl:with-param name="phone" select="WORKPHONE" />
							<xsl:with-param name="office" select="OFFICENUMBER" />
							<xsl:with-param name="officeaddress" select="WORKADDRESS" />
							<xsl:with-param name="officecity" select="WORKCITY" />
							<xsl:with-param name="officecountry" select="WORKCOUNTRY" />
							<xsl:with-param name="officephone" select="WORKPHONE" />
							<xsl:with-param name="officestate" select="WORKSTATE" />
							<xsl:with-param name="officezip" select="WORKZIP" />
							<xsl:with-param name="officeemail" select="WORKEMAIL" />
						</xsl:call-template>
					</div>
					<div class="psrch-Description">
						<xsl:choose>
							<xsl:when test="HITHIGHLIGHTEDSUMMARY[. != '']">
							
								<xsl:apply-templates select="HITHIGHLIGHTEDSUMMARY" />
							
							<br/>
						</xsl:when>

							<xsl:when test="ABOUTME[. != '']">
								<xsl:value-of disable-output-escaping="yes" select="ABOUTME"/>
								<br/>
							</xsl:when>
						</xsl:choose>
						<xsl:choose>
							<xsl:when test="RESPONSIBILITIES[. != ''] or SKILLS[. != '']">
								<xsl:choose>
									<xsl:when test="RESPONSIBILITIES[. != '']">
										<span class="psrch-PropLabel">
											<xsl:text>Responsibilities: </xsl:text>
										</span>
										<span class="psrch-PropValue">
											<xsl:value-of select="translate(RESPONSIBILITIES,';',',')"/>
											<xsl:text> </xsl:text>
										</span>
									</xsl:when>
								</xsl:choose>
								<xsl:choose>
									<xsl:when test="SKILLS[. != '']">
										<xsl:if test="RESPONSIBILITIES[. != ''] and SKILLS[. != '']">
											<br/>
										</xsl:if>
										<span class="psrch-PropLabel">
											<xsl:text>Skills: </xsl:text>
										</span>
										<span class="psrch-PropValue">
											<xsl:value-of select="translate(SKILLS,';',',')"/>
										</span>
									</xsl:when>
								</xsl:choose>
								<br/>
							</xsl:when>
							<xsl:otherwise>
								<span />
							</xsl:otherwise>
						</xsl:choose>
					</div>
					
				</td>
			</tr>
		</table>
	</xsl:template>

	<xsl:template name="OtherSearch">
		<xsl:variable name="id" select="WORKID"/>
		<xsl:variable name="url" select="PATH"/>

		<xsl:choose>
			<xsl:when test="PICTURETHUMBNAILURL[. !='']">
		<span class="srch-Icon">
			<a href="{$url}" id="{concat('CSR_IMG_',$id)}" title="{$url}">
				<img align="absmiddle" src="{PICTURETHUMBNAILURL}" border="0" alt="{TITLE}" />
			</a>
		</span>
			</xsl:when>
		</xsl:choose>
		<span class="srch-Title">
			<a href="{$url}" id="{concat('CSR_',$id)}" title="{$url}">
				<xsl:choose>
					<xsl:when test="HITHIGHLIGHTEDPROPERTIES/HHTitle[. != '']">
						<xsl:call-template name="HitHighlighting">
							<xsl:with-param name="hh" select="HITHIGHLIGHTEDPROPERTIES/HHTitle" />
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="TITLE"/>
					</xsl:otherwise>
				</xsl:choose>
			</a>
			<br/>
		</span>
		<xsl:choose>
			<xsl:when test="CONTENTCLASS[. = 'STS_ListItem_PictureLibrary'] and PICTURETHUMBNAILURL[. != '']">
				<div style="padding-top: 2px; padding-bottom: 2px;">
					<a href="{$url}" id="{concat('CSR_P',$id)}" title="{title}">
						<img src="{PICTURETHUMBNAILURL}" alt="" />
					</a>
				</div>
			</xsl:when>
		</xsl:choose>
		<div class="srch-Description">
			<xsl:choose>
				<xsl:when test="HITHIGHLIGHTEDSUMMARY[. != '']">
					<xsl:call-template name="HitHighlighting">
						<xsl:with-param name="hh" select="HITHIGHLIGHTEDSUMMARY" />
					</xsl:call-template>
				</xsl:when>
				<xsl:when test="DESCRIPTION[. != '']">
					<xsl:value-of select="DESCRIPTION"/>
				</xsl:when>
			</xsl:choose>
		</div >
		<p class="srch-Metadata">
			<span class="srch-URL">
				<a href="{$url}" id="{concat('CSR_U_',$id)}" title="{$url}" dir="ltr">
					<xsl:choose>
						<xsl:when test="HITHIGHLIGHTEDPROPERTIES/HHUrl[. != '']">
							<xsl:call-template name="HitHighlighting">
								<xsl:with-param name="hh" select="HITHIGHLIGHTEDPROPERTIES/HHUrl" />
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="URL"/>
						</xsl:otherwise>
					</xsl:choose>
				</a>
			</span>
			<xsl:call-template name="DisplaySize">
				<xsl:with-param name="size" select="SIZE" />
			</xsl:call-template>
			<xsl:call-template name="DisplayString">
				<xsl:with-param name="str" select="AUTHOR" />
			</xsl:call-template>
			<xsl:call-template name="DisplayString">
				<xsl:with-param name="str" select="WRITE" />
			</xsl:call-template>
		</p>
	</xsl:template>

	<!-- The size attribute for each result is prepared here -->
	<xsl:template name="DisplaySize">
		<xsl:param name="size" />
		<xsl:if test='string-length($size) &gt; 0'>
			<xsl:if test="number($size) &gt; 0">
				- <b>
					<xsl:choose>
						<xsl:when test="round($size div 1024) &lt; 1">
							<xsl:value-of select="$size" /> Bytes
						</xsl:when>
						<xsl:when test="round($size div (1024 *1024)) &lt; 1">
							<xsl:value-of select="round($size div 1024)" />KB
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="round($size div (1024 * 1024))"/>MB
						</xsl:otherwise>
					</xsl:choose>
				</b>
			</xsl:if>
		</xsl:if>
	</xsl:template>

	<xsl:template name="HitHighlighting">
		<xsl:param name="hh" />
		<xsl:apply-templates select="$hh"/>
	</xsl:template>

	<xsl:template name="everything">
		<xsl:copy-of select="*"/>
	</xsl:template>

	<xsl:template match="ddd">
		&#8230;
	</xsl:template>
	<xsl:template match="c0">
		<b>
			<xsl:value-of select="."/>
		</b>
	</xsl:template>
	<xsl:template match="c1">
		<b>
			<xsl:value-of select="."/>
		</b>
	</xsl:template>
	<xsl:template match="c2">
		<b>
			<xsl:value-of select="."/>
		</b>
	</xsl:template>
	<xsl:template match="c3">
		<b>
			<xsl:value-of select="."/>
		</b>
	</xsl:template>
	<xsl:template match="c4">
		<b>
			<xsl:value-of select="."/>
		</b>
	</xsl:template>
	<xsl:template match="c5">
		<b>
			<xsl:value-of select="."/>
		</b>
	</xsl:template>
	<xsl:template match="c6">
		<b>
			<xsl:value-of select="."/>
		</b>
	</xsl:template>
	<xsl:template match="c7">
		<b>
			<xsl:value-of select="."/>
		</b>
	</xsl:template>
	<xsl:template match="c8">
		<b>
			<xsl:value-of select="."/>
		</b>
	</xsl:template>
	<xsl:template match="c9">
		<b>
			<xsl:value-of select="."/>
		</b>
	</xsl:template>

	<xsl:template name="DisplayOfficeProfile">
		<xsl:param name="title" />
		<xsl:param name="dep" />
		<xsl:param name="phone" />
		<xsl:param name="office" />
		<xsl:param name="officeaddress"/>
		<xsl:param name="officecity"/>
		<xsl:param name="officecountry"/>
		<xsl:param name="officephone"/>
		<xsl:param name="officestate"/>
		<xsl:param name="officezip"/>
		<xsl:param name="officeemail"/>
		
		
		<span class="psrch-Metadata">
			<xsl:if test='string-length($title) &gt; 0'>
				<xsl:value-of select="$title" />
				-
			</xsl:if>
			<xsl:if test='string-length($dep) &gt; 0'>
				<xsl:value-of select="$dep" />
				-
			</xsl:if>
			<xsl:if test='string-length($phone) &gt; 0'>
				<xsl:value-of select="$phone" />
				-
			</xsl:if>
			<xsl:if test='string-length($office) &gt; 0'>
				<xsl:value-of select="$office" />
			</xsl:if>
		</span>
		<br/>
	</xsl:template>

	<!-- A generic template to display string with non 0 string length (used for author and lastmodified time -->
	<xsl:template name="DisplayString">
		<xsl:param name="str" />
		<xsl:if test='string-length($str) &gt; 0'>
			-
			<xsl:value-of select="$str" />
		</xsl:if>
	</xsl:template>

	<!-- document collapsing link setup -->
	
	<xsl:template name="replaceCharsInString">
		<xsl:param name="stringIn"/>
		<xsl:param name="charsIn"/>
		<xsl:param name="charsOut"/>
		<xsl:choose>
			<xsl:when test="contains($stringIn,$charsIn)">
				<xsl:value-of select="concat(substring-before($stringIn,$charsIn),$charsOut)"/>
				<xsl:call-template name="replaceCharsInString">
					<xsl:with-param name="stringIn" select="substring-after($stringIn,$charsIn)"/>
					<xsl:with-param name="charsIn" select="$charsIn"/>
					<xsl:with-param name="charsOut" select="$charsOut"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$stringIn"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

</xsl:stylesheet>
